import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description: 两数之和
 * User: 15085202591
 * Date: 2022-11-05
 * Time: 20:07
 */
public class SunNum {
    public static int[] sum(int[] array, int n){
        for (int i = 0; i < array.length; i++) {
            for (int j = i+1; j < array.length; j++) {
                if(array[i] + array[j] == n) {
                    return new int[]{i, j};
                }
            }
        }
        return new int[]{-1};
    }
    public static void main(String[] args) {
        int[] array = new int[]{2,7,9,11,20,22,27};
        System.out.println(Arrays.toString(array));
        System.out.println("求和为20");
        int[] array2 = sum(array,20);
        System.out.println(Arrays.toString(array2));
    }
}
